define(["moment", 'module/moduleB/program/B02/B0217/BadReasonService'], function (moment) {
    return ["$state", "$scope", "$rootScope", "$filter", "$stateParams", "config", "MMWService", "$mdDialog", "$timeout", "$calculater", 'BadReasonService', '$mddProvider',
        function ($state, $scope, $rootScope, $filter, $stateParams, config, $MMWService, $mdDialog, $timeout, $calculater, $BadReasonService, $mddProvider) {
            $scope._event = {};
            $scope.qms=false;

            $scope.init = function () {
                // $scope.$root.hideMenu();
                // console.log('config.module',config.module);
                //20220221 add BY 10877 FOR MTS0107482 ========(S)========
                $scope.os_back_setting = false;   //外包回貨顯示(標準/進階)

                //顯示模式紀錄
                if (typeof (Storage) !== 'undefined') {
                    $scope.os_back_setting = JSON.parse(localStorage.getItem(config.appName + 'OSbackSetting'));
                }

                $scope.osvaluationinput = config.cache.sys_parameter['OSValuationInput'];   //外包進貨計價控管  
                $scope.osbacknotallowedexceed = config.cache.sys_parameter['OSBackNotAllowedExceed'];    //外包回貨可超收量    
                $scope.outsourcing_info_detail_C = [];    //紀錄選取單身，用來做檢驗狀態檢查
                //20220221 add BY 10877 FOR MTS0107482 ========(E)========
                config.module.forEach(function (item) {
                    if(item.name==="modulesSPC"){ 
                        $scope.qms=true;
                    }     
                })
                $MMWService.PNIGList = {};
                $scope.outsourcing_info_detail=[];
                $scope.outsourcers = {
                    erp_doc_type: "",
                    outsourcers_no:"",
                    outsourcers_company_no:"",
                    outsourcing_back_info_detail: []
                };
                $scope.itemList = [];
                $scope.C00_require_condition = true;
                $scope.codeList = [
                    {name:$filter('translate')('B0217.list.outsource_no'), column_name:'A.OSNO', column_query:loadOutsource},
                    {name:$filter('translate')('B0217.list.outsourcers_no'), column_name:'B.SubcontractorNo', column_query:loadOutsourcer},
                    {name:$filter('translate')('B0217.list.column02'), column_name:'C.MONo', column_query:loadWoInfo},
                    {name:$filter('translate')('B0217.list.column03'), column_name:'A.LOTNO', column_query:loadPlotInfo}
                ];
                $scope.CheckQC = config.cache.sys_parameter.CheckQC; // 是否開啟驗退數
                $scope.FasteningPackage = config.cache.sys_parameter.FasteningPackage; // 扣件行業包
                if($scope.FasteningPackage == 1 || $scope.FasteningPackage == 'Y'){
                    vehicle_no_info_get('', function(itemList){
                        $scope.vehicleList = itemList; // 載具list
                    });
                }
                //20220224 add by 10877 for M#107481 
                $scope.state = '0';
                $MMWService.pageNumberInfoGet({
                    page_mode: 'tblsyserpsetting_get'
                }, function (itemList) {
                    if (itemList.length != 0) {
                        if (itemList[0].erp_name === 'WFGP') {//當整合ERP產品為WFGP時
                            $scope.ERPisWF = '1';
                        } else {
                            $scope.ERPisWF = '0';
                        }
                    } else {
                        $scope.ERPisWF = '0';
                    }

                });
            };

            $scope.back = function () {
                $scope.$root.hideMenu();
                $scope.$root.changeProgram('home', true);
            };

            $scope.barcodeScan = function (event) {
                if (event.keyCode == 13) {
                    $scope.search();
                }
            };

            //20220221 add BY 10877 FOR MTS0107482 ========(S)========
            $scope.setting = function () {
                $mdDialog.serviceDialog('OSbackSettingService', {
                    os_back_setting: angular.copy($scope.os_back_setting),
                    parent: 'B0217',
                    callback: function (dialog) {
                        $scope.os_back_setting = dialog.os_back_setting;
                        localStorage.setItem(config.appName + 'OSbackSetting', JSON.stringify($scope.os_back_setting));
                        dialog.hide();
                        $scope.beforeSearch();
                    }
                });
            };

            $scope.panelInput = function (event, item) {
                if (item.osstatus != '0')
                    return;
                var target = event.currentTarget;
                itemList = angular.copy(item);
                angular.element(target).addClass('is-focus');
                $mdDialog.serviceDialog('panelInputService', {
                    itemList: itemList,
                    parent: 'B0217',
                    callback: function (dialog) {
                        item.returned_qty = dialog.itemList.returned_qty;
                        item.excessqty = dialog.itemList.excessqty;
                        item.abnormal_qty = dialog.itemList.abnormal_qty;
                        item.return_qty = dialog.itemList.return_qty;
                        item.lossqty = dialog.itemList.lossqty;
                        item.issuedefectqty = dialog.itemList.issuedefectqty;
                        item.valuationqty = dialog.itemList.valuationqty;
                        item.valuationqty_no = dialog.itemList.valuationqty_no;
                        item.abnormal_detail = dialog.itemList.abnormal_detail;
                        dialog.hide();
                    }
                });
            };
            //20220221 add BY 10877 FOR MTS0107482 ========(E)========

            // 不良原因
            $scope.openBadReason = function (item) {
                //20220224 add by 10877 for M#107481 
                if ($scope.state === '1') {
                    //跑ERP檢驗不能修改
                } else {

                    $BadReasonService.init({
                        parent: 'B0217',
                        plot_no: item.plot_no,
                        op_no: item.op_no,
                        abnormal_detail: angular.copy(item.abnormal_detail),
                        callback: function (dialog) {
                            // 調整回貨不良數和驗退數，自動扣減良品數
                            // 回貨良品數 = 目前的回貨良品數(輸入之後) - (回貨不良數 - 上次紀錄回貨不良數 )
                            if ((+item.abnormal_qty) == (+dialog.total_abnormal_qty)) {
                                dialog.hide();
                                return;
                            }
                            //20220221 modify BY 10877 FOR MTS0107482  ========(S)========
                            // var good_qty = +(item.returned_qty) - (+(dialog.total_abnormal_qty) - (+item.abnormal_qty));
                            // if(good_qty >= 0){
                            //     item.abnormal_detail = dialog.badReasonInfo;
                            //     item.abnormal_qty = dialog.total_abnormal_qty; // 回貨不良數
                            //     item.returned_qty = good_qty; // 回貨良品數
                            //     dialog.hide();
                            // } else {
                            //     // 回貨良品數不能小於 0！
                            //     return $scope.$root.showAlert($filter('translate')('B0217.showAlert.column8'));
                            // }
                            item.abnormal_detail = dialog.badReasonInfo;
                            item.abnormal_qty = dialog.total_abnormal_qty; // 回貨不良數
                            dialog.hide();
                            //20220221 modify BY 10877 FOR MTS0107482  ========(E)========
                        }
                    });
                }
            };
        
            //  $scope.stopConfirm=function(){
            //     return $scope.outsourcing_info_detail.some(function(item){
            //         return ((+item.abnormal_qty) + (+item.returned_qty))===0
            //     })
            // }

            $scope.confirm = function () {
                var msg = '';
                var content = {
                    outsourcers_no: $scope.outsourcers.outsourcers_no,
                    outsourcing_info_detail: [],
                    erp_doc_type: $scope.outsourcers.erp_doc_type
                    , chkdefault_os_return_qcflag: $scope.state  //20220224 add by 10877 for M#107481 0:SMES檢驗(PKG) 、 1:ERP檢驗
                };

                if ($scope.itemList.length > 0) {
                    $scope.itemList.forEach(function (item) {
                        if (item.isSelect) {
                            //20220221 add BY 10877 FOR MTS0107482  ========(S)========
                            msg = Qty_check(item, msg);
                            //20220221 add BY 10877 FOR MTS0107482  ========(E)========
                            content.outsourcing_info_detail.push({
                                outsource_no: item.outsource_no,
                                plot_no: item.plot_no,
                                // 20200624 modify by WeiTing for M#73768 - 回貨良品數固定使用 returned_qty
                                // input_qty: $scope.getQty(item),
                                //20220221 modify BY 10877 FOR MTS0107482  ========(S)========
                                // 良品數已包含多於數
                                // input_qty: item.returned_qty,
                                input_qty: (+item.returned_qty) - (+item.excessqty),
                                //20220221 modify BY 10877 FOR MTS0107482  ========(E)========
                                abnormal_qty: item.abnormal_qty,
                                abnormal_detail: item.abnormal_detail,
                                spc:item.spc, /*20200526 Oliver for 72467 SPC與檢驗清單欄位新增*/
                                qc_control:item.qc_control,/*20200526 Oliver for 72467 SPC與檢驗清單欄位新增*/
                                spc_ok:item.spc_ok,/*20200526 Oliver for 72467 SPC與檢驗清單欄位新增*/
                                qc_form_no:item.qc_form_no,
                                spc_ok_qty:item.spc_ok_qty,
                                spc_ng_qty:item.spc_ng_qty,
                                return_qty:item.return_qty, // 驗退數
                                op_no: item.op_no,
                                fastening_info_detail: item.fastening_info_detail,
                                //20220221 add BY 10877 FOR MTS0107482  ========(S)========
                                excessqty: item.excessqty,   //多於數
                                lossqty: item.lossqty,   //短少
                                issuedefectqty: item.issuedefectqty, //發料不良
                                valuationqty: item.valuationqty, //計價數量
                                qcformno: item.qcformno, //檢驗單號
                                //20220221 add BY 10877 FOR MTS0107482  ========(E)========
                                osstatus: item.osstatus,
                                good_qty: item.returned_qty // 20230810 add by wenwei for M#142497 ERP檢驗-數據回寫異常
                            });
                        }
                    });
                } else {
                    msg += $filter('translate')('B0217.showAlert.column4');
                }

                if(content.outsourcing_info_detail.length == 0){
                    msg += $filter('translate')('B0217.showAlert.column5');
                }
                /*20200526 Oliver for 72467 SPC與檢驗清單欄位新增
                if(typeof $scope.itemList.qc_form_no!='undefined'){//防呆，如果真的有回傳檢驗清單才執行判斷
                    var checkList_not_null = content.outsourcing_info_detail.some(function(item){
                        return item.qc_form_no!='' && item.spc_ok=="N";//所有要送出的資料內的檢驗清單如果有一個有值就為真，就不給送
                    });
                    if(checkList_not_null){//只要有檢驗清單就不送出
                        msg += $filter('translate')('B0217.showAlert.column7');
                    }
                }*/ 
                
                //20200120 韋齊 for 66844 將ERP設定不為空的卡控註解掉
                //  else if($scope.outsourcers.erp_doc_type === ''){
                //     msg += $filter('translate')('B0217.showAlert.column6');
                // }

                if(msg == ''){
                    // content.outsourcing_info_detail.forEach(function(item){
                    //     delete item.qc_form_no;
                    // })
                    fasteningCheck(content.outsourcing_info_detail, function(){
                        $MMWService.sendToServer({
                            uri: 'ServicesSTD.Module_WIP.outsourcing_back_process',
                            content: content,
                            success: function (data, response) {
                                showProcessResultMsg(data, response) ;
                                $scope.beforeSearch();
                            },
                            error: function(res){
                                $scope.$root.showAlert(res.Message)
                                $scope.beforeSearch();
                            }
                        });
                    });
                } else {
                    $scope.$root.showAlert(msg);
                }
            };

            // 顯示進貨執行結果
            function showProcessResultMsg(returnData, response){
                var msg = '';
                var success_detail = returnData.outsourcing_back_process_success;
                var fail_detail = returnData.outsourcing_back_process_fail;
                var msg_level = '';
                if(success_detail && success_detail.length > 0){
                    success_detail.forEach(function(item){
                        msg += item.description + '<br>';
                    });
                }
                if(fail_detail && fail_detail.length > 0){
                    msg_level = 'error';
                    fail_detail.forEach(function(item){
                        msg += item.description + '<br>';
                    });
                }
                msg = msg || response.Message || $filter('translate')('B0217.showAlert.column1');
                $rootScope.showToast(msg, msg_level);
            }

            $scope.loadERP = function () {
                $rootScope.showQueryList({
                    pageRecord:50,
                    header : [
                        {label:$filter('translate')('B0216.queryList.column3_1'), code:'page_no'},
                        {label:$filter('translate')('B0216.queryList.column3_2'), code:'page_name'}
                    ],
                    query: function(conditions, feedback){
                        $MMWService.sendToServer({
                            uri: 'ServicesSTD.Module_SYS.erp_document_type_get',
                            content: {
                                doc_type: '5',
                                chkdefault_os_return_qcflag: $scope.state
                            },//20220224 add by 10877 for M#107481 0:SMES檢驗(PKG) 、 1:ERP檢驗
                            success: function (data) {
                                feedback(data);
                            }
                        });
                    },
                    selectCode:$scope.outsourcers.erp_doc_type,
                    confirm : function(selectItem, dialog){
                        dialog.hide();
                        $scope.outsourcers.erp_doc_display = selectItem.page_no + ' ('+selectItem.page_name+')';
                        $scope.outsourcers.erp_doc_type = selectItem.page_no;
                    }
                });
            };

            //單號資訊取得
            $scope.search = function(condition){
                $scope.outsourcing_info_detail_C = [];    //20220221 add BY 10877 FOR MTS0107482
                $MMWService.sendToServer({
                    uri: 'ServicesSTD.Module_WIP.outsourcing_info_get',
                    content: {
                        query_condition: condition,
                        return_type: 1,
                        chkdefault_os_return_qcflag: $scope.state//20220224 add by 10877 for M#107481 0:SMES檢驗(PKG) 、 1:ERP檢驗
                    },
                    success: function (data) {
                        data.outsourcing_back_info_detail.forEach(function (item) {
                            item.isSelect = false;
                            // item.max_qty = item.returned_qty;
                            item.qty = item.returned_qty;
                            //item.abnormal_qty = 0;  //20220221 mark BY 10877 FOR MTS0107482
                            item.abnormal_detail = [];
                            //20220221 add BY 10877 FOR MTS0107482  ========(S)========
                            // item.return_qty = 0; // 驗退數
                            item.can_returned_qty = item.returned_qty; //外包可回貨量
                            //20220221 add BY 10877 FOR MTS0107482  ========(E)========
                            item.origin_qty = item.returned_qty; // 保存原本的回貨良品數

                            //20220221 add BY 10877 FOR MTS0107482  ========(S)========
                            // 如果單號狀態是 0 (待回貨)
                            if (item.osstatus == '0') {
                                // 重工工單/其他工單預設計價數量
                                if (item.plot_no.indexOf('RW') != -1) {
                                    item.valuationqty = item.issuedefectqty;
                                    item.valuationqty_no = item.returned_qty;
                                } else {
                                    item.valuationqty = (+item.returned_qty) + (+item.issuedefectqty);
                                    item.valuationqty_no = 0;  //計價數量(不計) //20220221 add BY 10877 FOR MTS0107482                                              
                                }
                            } else {
                                // 單號狀態 1.送驗中，2.待入庫
                                // 計價數量(不計) = 回貨良品數 + 發貨不良 + 多於數 - 計價數量(計)
                                item.valuationqty_no = (+item.returned_qty) + (+item.issuedefectqty) - (+item.valuationqty);
                                // 回貨良品數 = 回貨良品數 + 多於數
                                item.returned_qty = item.returned_qty;
                            }

                            //20220221 add BY 10877 FOR MTS0107482  ========(E)========

                            // 有開啟紧固件行业包時，如果有預設載具編號，需要在額外取得此載具編號的資訊
                            if($scope.FasteningPackage == 1 || $scope.FasteningPackage == 'Y'){
                                if(item.fastening_info_detail.defaultvehicle){
                                    for(var i = 0; $scope.vehicleList.length; i++){
                                        if(item.fastening_info_detail.defaultvehicle == $scope.vehicleList[i].vehicle_no){
                                            item.fastening_info_detail.vehicle_no = $scope.vehicleList[i].vehicle_no;
                                            item.fastening_info_detail.vehicle_name = $scope.vehicleList[i].vehicle_name;
                                            item.fastening_info_detail.vehicle_weight = $scope.vehicleList[i].vehicle_weight;
                                            item.fastening_info_detail.vehicle_capacity = $scope.vehicleList[i].vehicle_capacity;
                                            break;
                                        } else {
                                            item.fastening_info_detail.vehicle_no = '';
                                            item.fastening_info_detail.vehicle_name = '';
                                            item.fastening_info_detail.vehicle_weight = '';
                                            item.fastening_info_detail.vehicle_capacity = '';
                                        }
                                    }
                                } else {
                                    item.fastening_info_detail.vehicle_no = '';
                                    item.fastening_info_detail.vehicle_name = '';
                                    item.fastening_info_detail.vehicle_weight = '';
                                    item.fastening_info_detail.vehicle_capacity = '';
                                } 
                            }
                        });
                        $scope.outsourcers.outsourcers_company_no = data.outsourcers_no;
                        $scope.itemList = data.outsourcing_back_info_detail;
                    },
                    error_callback:function(data){
                        $scope.workItemList = [];
                    }
                });
            };

            $scope.itemCheck = function (index, item) {
                //20220221 modify BY 10877 FOR MTS0107482  ========(S)========
                //不同檢驗狀態不可同時勾選送出
                // item.isSelect = !item.isSelect;
                // if(item.isSelect==true){
                //     $scope.outsourcing_info_detail.push(item);
                // }else{
                //     $scope.outsourcing_info_detail.splice($scope.outsourcing_info_detail.indexOf(item),1);
                // }
                if (Osstatus_check(item)) {
                    item.isSelect = !item.isSelect;
                    if (item.isSelect == true) {
                        $scope.outsourcing_info_detail.push(item);
                        $scope.outsourcing_info_detail_C.push(item);
                    } else {
                        $scope.outsourcing_info_detail.splice($scope.outsourcing_info_detail.indexOf(item), 1);
                        $scope.outsourcing_info_detail_C.splice($scope.outsourcing_info_detail_C.indexOf(item), 1);
                    }
                }else{
                    $scope.$root.showAlert($filter('translate')('B0217.showAlert.column11'));
                    return;
                }
                //20220221 modify BY 10877 FOR MTS0107482  ========(E)========
            };

            // 20200624 modify by WeiTing for M#73768 - 回貨良品數固定使用 returned_qty
            // $scope.getQty = function (item) {
            //     if (!item.qty) {
            //         return item.returned_qty;
            //     } else {
            //         return item.qty;
            //     }
            // };
            $scope.input_qty = function (event, item) {
                var target = event.currentTarget;
                angular.element(target).addClass('is-focus');
                $calculater.open(function (num, dialog) {
                        //if ((+num) > (+item.max_qty)) {
                        //    $scope.$root.showAlert($filter('translate')('B0217.showAlert.column3') + item.output_qty);
                        //} else {
                            // 20200624 modify by WeiTing for M#73768 - 回貨良品數固定使用 returned_qty
                            // item.returned_qty = item.qty = num;
                    //20220221 modify BY 10877 FOR MTS0107482  ========(S)========
                    // item.returned_qty = num;
                    // angular.element(target).removeClass('is-focus');
                    // dialog.hide();
                    if ((+item.returned_qty) == (+num)) {
                        angular.element(target).removeClass('is-focus');
                        dialog.hide();
                        return;
                    } else {
                        if (((+num) > (+item.can_returned_qty)) && ($scope.osbacknotallowedexceed == "1")) {
                            $rootScope.showAlert($filter('translate')('panelInput.msg.OSReceipt_Qtyover'));       //外包超收                                           
                        } else {
                            item.returned_qty = num;
                            angular.element(target).removeClass('is-focus');
                            alter_valuationqty(item);
                            dialog.hide();
                        }
                    }
                    //20220221 modify BY 10877 FOR MTS0107482  ========(E)========
                        //}
                    },
                    function (dialog) {
                        angular.element(target).removeClass('is-focus');
                        dialog.hide();
                    },
                    {
                        // 20200624 modify by WeiTing for M#73768 - 回貨良品數固定使用 returned_qty
                        // defaultNum: item.qty,
                        defaultNum: item.returned_qty,
                        decimalLength: 4 //20180531 modify by Dustdusk for M#47421:回貨小數位數開啟
                    });
            };

            // 更改驗退數
            $scope.changeReturnQty = function (event, item) {
                //20220224 add by 10877 for M#107481
                if ($scope.state === '1') {
                    //跑ERP檢驗不能修改
                } else {
                    var target = event.currentTarget;
                    angular.element(target).addClass('is-focus');
                    $calculater.open(function (num, dialog) {
                        // 調整回貨不良數和驗退數，自動扣減良品數
                        // 回貨良品數 = 目前的回貨良品數(輸入之後) - (驗退數 - 上次紀錄驗退數)
                        if ((+item.return_qty) == (+num)) {
                            angular.element(target).removeClass('is-focus');
                            dialog.hide();
                            return;
                        }
                        //20220221 modify BY 10877 FOR MTS0107482  ========(S)========
                        // var good_qty = +(item.returned_qty) - (+(num) -(+item.return_qty));
                        // if(good_qty >= 0){
                        //     item.return_qty = num; // 驗退數
                        //     item.returned_qty = good_qty; // 回貨不良數
                        //     angular.element(target).removeClass('is-focus');
                        //     dialog.hide();
                        // } else {
                        //     // 回貨良品數不能小於 0！
                        //     return $scope.$root.showAlert($filter('translate')('B0217.showAlert.column8'));
                        // }
                        item.return_qty = num;
                        angular.element(target).removeClass('is-focus');
                        dialog.hide();
                        //20220221 modify BY 10877 FOR MTS0107482  ========(E)========
                    },
                    function (dialog) {
                        angular.element(target).removeClass('is-focus');
                        dialog.hide();
                    },
                    {
                        defaultNum: item.return_qty,
                        decimal: false
                    });
                }
            };

            $scope.callB0225 = function(item){
                $mdDialog.serviceDialog('B0202Service',{
                    parent:'B0217',
                    plotItem : item,
                    callback : function(){
                        $scope.search();
                    }
                });
            };

            //20220224 add by 10877 for M#107481
            $scope.changestate = function (mstate) {
                $scope.$root.showConfirm($filter('translate')('B0217.msg.is_changestate'),
                 function (confirmDialog) {
                     if (mstate == '1') {//有異動回貨『檢驗』條件都要重新查詢
                         //ERP驗證
                         $scope.state = '1'; //ERP檢驗
                         $scope.outsourcers.erp_doc_type = '';     //ERP單號
                         $scope.outsourcers.erp_doc_display = '';  //ERP顯示
                         $scope.itemList = ''; //單身LIST


                     } else {
                         //SMES驗證
                         $scope.state = '0';//sMES檢驗
                         $scope.outsourcers.erp_doc_type = '';    //ERP單號
                         $scope.outsourcers.erp_doc_display = ''; //ERP顯示
                         $scope.itemList = '';      //單身LIST       
                         //       
                     }
                     confirmDialog.hide();
                     $timeout(function () {
                         $scope.favorite(function () {

                         });
                     }, 200);
                 });
            }

            //外包單號開窗查詢
            function loadOutsource(item){
                $MMWService.showQueryListPNIG({
                    // page_mode: 9,
                    form_name: 'PageNo_54',
                    pageRecord:50,
                    condition: [
                        {name:$filter('translate')('B0217.queryList.column1_1'), column_name:'WOB.OSNO', query_mode:'0', value:item.value}
                    ],
                    header: [
                        {label:$filter('translate')('B0217.queryList.column1_1'), code:'page_no'}
                    ],
                    setCondition:function(conditions){
                        return conditions;
                    },
                    selectCode:item,
                    confirm : function(selectItem){
                        $scope.condition_item.value = selectItem.page_no;
                    }
                });
            }

            //外包商編號開窗查詢
            function loadOutsourcer(item){
                $MMWService.showQueryListPNIG({
                    form_name:'PageNo_91',
                    // page_mode: 'out_subcontractor_info_get',
                    pageRecord:50,
                    condition: [
                        {name:$filter('translate')('B0217.list.outsourcers_no'), column_name:'t2.SubcontractorNo', query_mode:'0', value:item.value},
                        {name:$filter('translate')('B0217.list.outsourcers_name'), column_name:'t2.SubcontractorName', query_mode:'0', value:item.value}
                    ],
                    header: [
                        {label:$filter('translate')('B0217.list.outsourcers_no'), code:'subcontractorno'},
                        {label:$filter('translate')('B0217.list.outsourcers_name'), code:'subcontractorname'},
                        {label:$filter('translate')('common.queryList.description'), code:'description'}
                    ],
                    setCondition:function(conditions){
                        return conditions;
                    },
                    selectCode:item.value,
                    confirm : function(selectItem){
                        $scope.condition_item.value = selectItem.subcontractorno;
                    }
                });
            }

            //已出貨工單資訊取得
            function loadWoInfo(item){
                $MMWService.showQueryListPNIG({
                    form_name:'PageNo_89',
                    // page_mode: 'out_mono_info_get',
                    pageRecord:50,
                    condition: [
                        {name:$filter('translate')('B0217.list.outsourcers_no'), column_name:'d.MONO', query_mode:'0', value:item.value}
                    ],
                    header: [
                        {label:$filter('translate')('B0217.list.column02'), code:'mono'}
                    ],
                    setCondition:function(conditions){
                        return conditions;
                    },
                    selectCode:item.value,
                    confirm : function(selectItem){
                        $scope.condition_item.value = selectItem.mono;
                    }
                });
            }

            //已出貨生產批資訊取得
            function loadPlotInfo(item){
                $MMWService.showQueryListPNIG({
                    form_name:'PageNo_90',
                    // page_mode: 'out_plot_info_get',
                    pageRecord:50,
                    condition: [
                        {name:$filter('translate')('B0217.list.column03'), column_name:'c.LOTNO', query_mode:'0', value:item.value}
                    ],
                    header: [
                        {label:$filter('translate')('B0217.list.column03'), code:'lotno'}
                    ],
                    setCondition:function(conditions){
                        return conditions;
                    },
                    selectCode:item.value,
                    confirm : function(selectItem){
                        $scope.condition_item.value = selectItem.lotno;
                    }
                });
            }

            // 雙單位計算進站數量
            $scope.calculaterVehicleQty = function(event, VehicleQty, item){ 
                //依照need_vehicle判斷進站是否需要維護載具資訊
                if(!item.fastening_info_detail.vehicle_name
                    || item.fastening_info_detail.vehicle_name == ''){
                    if(item.fastening_info_detail.need_vehicle == 2){
                        //無維護載具編號，請問是否繼續執行
                        $rootScope.showAlert($filter('translate')('B0206.msg.vehicle_info_empty'));
                        return;
                    }
                }   
                var target = event.currentTarget;
                angular.element(target).addClass('is-focus');
                if(item.fastening_info_detail.molecule > 0 && item.fastening_info_detail.denominator > 0){
                    $calculater.open(function(num,calcDialog){
                        angular.element(target).removeClass('is-focus');
                        if(+num <= 0){
                            // 雙單位數量不能小於等於0
                            $rootScope.showAlert($filter('translate')('B0217.vehicleMsg.column6'));
                        } else {
                            var _checkout_qty = calculaterVehicleQtyCallback(+num, item);
                            if(_checkout_qty > 0){
                                if(_checkout_qty > item.qty){
                                    // 轉換數量 + _checkout_qty + 超出可出貨數量 + item.qty +，轉換失敗，請重新輸入
                                    return $rootScope.showAlert($filter('translate')('B0217.vehicleMsg.column1') + _checkout_qty 
                                        + $filter('translate')('B0217.vehicleMsg.column4') + item.qty
                                        + $filter('translate')('B0217.vehicleMsg.column7'));
                                } else {
                                    item.fastening_info_detail.double_unit_qty = (+num);
                                    item.fastening_info_detail.vehicle_qty = _checkout_qty;
                                    item.returned_qty = _checkout_qty;
                                    calcDialog.hide();
                                }
                            } else {
                                // 轉換數量 + _checkout_qty + 小於等於0，轉換失敗，請重新輸入
                                return $rootScope.showAlert($filter('translate')('B0217.vehicleMsg.column1') + _checkout_qty 
                                    + $filter('translate')('B0217.vehicleMsg.column2') + $filter('translate')('B0217.vehicleMsg.column7'));
                            }
                        }
                    },
                    function(calcDialog){
                        angular.element(target).removeClass('is-focus');
                        calcDialog.hide();
                    },
                    {
                        defaultNum : VehicleQty,
                        decimal : true
                    });
                } else {
                    // 雙單位轉換率分子或分母不得為0
                    $rootScope.showAlert($filter('translate')('B0217.vehicleMsg.column3'));
                }
            }

            // 雙單位計算進站數量callback
            function calculaterVehicleQtyCallback(num, item){ 
                var _checkout_qty = CaculateFastening(item.fastening_info_detail, (+num));
                if(item.fastening_info_detail.double_unit_rules == 3){ // 3: 转换数量超出可回货良品数则取可回货良品数
                    if(+_checkout_qty > +item.qty){
                        _checkout_qty = +item.qty;
                    }
                } else if(item.fastening_info_detail.double_unit_rules == 4){ // 4: 转换数量小于可回货良品数取可回货良品数
                    if(+_checkout_qty < +item.qty){
                        _checkout_qty = +item.qty;
                    }
                } 
                return +_checkout_qty || 0;
            }

            // 更換雙單位轉換率分子
            $scope.changeMoleculeValue = function(event, item){ 
                var target = event.currentTarget;
                angular.element(target).addClass('is-focus');
                $calculater.open(function(num,calcDialog){
                    angular.element(target).removeClass('is-focus');
                    if(item.fastening_info_detail.double_unit_qty){
                        var originMoleculeValue = item.fastening_info_detail.molecule; // 先保留原本的轉換率分子
                        if(+num == 0){
                            // 已經輸入雙單位數量，不能變更為0
                            return $rootScope.showAlert($filter('translate')('B0217.vehicleMsg.column5'));
                        } else {
                            item.fastening_info_detail.molecule = (+num); // 先更換轉換率分子進行計算，轉換失敗會在還原
                            var _checkout_qty = calculaterVehicleQtyCallback(+item.fastening_info_detail.double_unit_qty, item);
                            if(_checkout_qty > 0){
                                if(_checkout_qty > item.qty){
                                    item.fastening_info_detail.molecule = originMoleculeValue; // 轉換失敗，需還原原本的轉換率分子
                                    // 轉換數量 + _checkout_qty + 超出可出貨數量 + item.qty +，轉換失敗，請重新輸入
                                    return $rootScope.showAlert($filter('translate')('B0217.vehicleMsg.column1') + _checkout_qty 
                                        + $filter('translate')('B0217.vehicleMsg.column4') + item.qty
                                        + $filter('translate')('B0217.vehicleMsg.column7'));
                                } else {
                                    item.fastening_info_detail.molecule = (+num);
                                    item.fastening_info_detail.vehicle_qty = _checkout_qty;
                                    item.returned_qty = _checkout_qty;
                                    calcDialog.hide();
                                }
                            } else {
                                // 轉換數量 + _checkout_qty + 小於等於0，轉換失敗，請重新輸入
                                return $rootScope.showAlert($filter('translate')('B0217.vehicleMsg.column1') + _checkout_qty 
                                    + $filter('translate')('B0217.vehicleMsg.column2') + $filter('translate')('B0217.vehicleMsg.column7'));
                            }
                        }
                    } else {
                        item.fastening_info_detail.molecule = (+num);
                        calcDialog.hide();
                    }
                },
                function(calcDialog){
                    angular.element(target).removeClass('is-focus');
                    calcDialog.hide();
                },
                {
                    defaultNum : item.fastening_info_detail.molecule,
                    decimal : true
                });
            }

            // 更換雙單位轉換率分母
            $scope.changeDenominatorValue = function(event, item){ 
                var target = event.currentTarget;
                angular.element(target).addClass('is-focus');
                $calculater.open(function(num,calcDialog){
                    angular.element(target).removeClass('is-focus');
                    var originDenominatorValue = item.fastening_info_detail.denominator; // 先保留原本的轉換率分母
                    if(item.fastening_info_detail.double_unit_qty){
                        if(+num == 0){
                            // 已經輸入雙單位數量，不能變更為0
                            return $rootScope.showAlert($filter('translate')('B0217.vehicleMsg.column5'));
                        } else {
                            item.fastening_info_detail.denominator = (+num); // 先更換轉換率分母進行計算，轉換失敗會在還原
                            var _checkout_qty = calculaterVehicleQtyCallback(+item.fastening_info_detail.double_unit_qty, item);
                            if(_checkout_qty > 0){
                                if(_checkout_qty > item.qty){
                                    item.fastening_info_detail.denominator = originDenominatorValue; // 轉換失敗，需還原原本的轉換率分母
                                    // 轉換數量 + _checkout_qty + 超出可出貨數量 + item.qty +，轉換失敗，請重新輸入
                                    return $rootScope.showAlert($filter('translate')('B0217.vehicleMsg.column1') + _checkout_qty 
                                        + $filter('translate')('B0217.vehicleMsg.column4') + item.qty
                                        + $filter('translate')('B0217.vehicleMsg.column7'));
                                } else {
                                    item.fastening_info_detail.denominator = (+num);
                                    item.fastening_info_detail.vehicle_qty = _checkout_qty;
                                    item.returned_qty = _checkout_qty;
                                    calcDialog.hide();
                                }
                            } else {
                                // 轉換數量 + _checkout_qty + 小於等於0，轉換失敗，請重新輸入
                                return $rootScope.showAlert($filter('translate')('B0217.vehicleMsg.column1') + _checkout_qty 
                                    + $filter('translate')('B0217.vehicleMsg.column2') + $filter('translate')('B0217.vehicleMsg.column7'));
                            }
                        } 
                    } else {
                        item.fastening_info_detail.denominator = (+num);
                        calcDialog.hide();
                    }
                },
                function(calcDialog){
                    angular.element(target).removeClass('is-focus');
                    calcDialog.hide();
                },
                {
                    defaultNum : item.fastening_info_detail.denominator,
                    decimal : true
                });
            }

            // 開窗選擇載具編號
            $scope.loadVehicleList = function(item){ 
                $rootScope.showQueryList({
                    header: [
                        {label:$filter('translate')('B0206.trackOut.vehicle_no'), code:'vehicle_no'},
                        {label:$filter('translate')('B0206.trackOut.vehicle_name'), code:'vehicle_name'},
                        {label:$filter('translate')('B0206.trackOut.vehicle_weight'), code:'vehicle_weight'},
                        {label:$filter('translate')('B0206.trackOut.vehicle_capacity'), code:'vehicle_capacity'}
                    ],
                    query: function(conditions, feedback){
                        vehicle_no_info_get('', feedback);
                    },
                    selectCode:item.fastening_info_detail.vehicle_no,
                    confirm : function(selectItem, query_dialog){
                        item.fastening_info_detail.vehicle_no = selectItem.vehicle_no;
                        item.fastening_info_detail.vehicle_name = selectItem.vehicle_name;
                        item.fastening_info_detail.vehicle_weight = selectItem.vehicle_weight;
                        item.fastening_info_detail.vehicle_capacity = selectItem.vehicle_capacity;
                        item.fastening_info_detail.double_unit_qty = undefined; // 有載具編號的情況，雙單位計算公式會不同，所以刷新載具編號時，也要重新輸入雙單位數量
                        query_dialog.hide();
                    }
                });
            }

            //雙單位計算進站數量
            function CaculateFastening(fastening_info, qty){
                var _qty = $calculater.decimalMutiple($calculater.decimalSub(qty, fastening_info.vehicle_weight||0), (fastening_info.molecule||1)) / (fastening_info.denominator||1),
                    _accuracy = Math.pow(10, fastening_info.accuracy||0)||1;;
                if(fastening_info.conversion_rules == 0){
                    //無條件進位
                    _qty = Math.ceil(_qty * _accuracy) / _accuracy;
                } else if(fastening_info.conversion_rules == 1){
                    //無條件捨��?
                    _qty = Math.floor(_qty * _accuracy) / _accuracy;
                } else if(fastening_info.conversion_rules == 2){
                    //四捨五入
                    _qty = Math.round(_qty * _accuracy) / _accuracy;
                }
                return _qty;
            }

            //取得載具資訊
            function vehicle_no_info_get(vehicle_no, callback){
                var query_condition_info = [];
                if(vehicle_no && vehicle_no != '')
                    query_condition_info.push({column_name:'VehicleNo', query_mode:'0', value: vehicle_no, merge_condition_model:'AND'});
                $MMWService.pageNumberInfoGet({
                    page_mode : 'vehicle_no_info_get',
                    query_condition_info:query_condition_info
                }, function(itemList){
                    if(callback)
                        callback(itemList);
                });
            }

            //扣件資訊檢查
            function fasteningCheck(options, callback){
                console.log(options);
                var msg = '', warring_msg = '';
                //依照need_vehicle判斷進站是否需要維護載具資訊?
                if(config.cache.sys_parameter['FasteningPackage'] == 1){
                    if(options && options.length > 0){
                        for(var i = 0; i < options.length; i++){
                            if(!options[i].fastening_info_detail.vehicle_name
                                || options[i].fastening_info_detail.vehicle_name == ''){
                                if(options[i].fastening_info_detail.need_vehicle == 1){
                                    // 批號： item.plot_no 無維護載具編號，請問是否繼續執行
                                    warring_msg += ($filter('translate')('B0216.showAlert.column5') + options[i].plot_no 
                                        + $filter('translate')('B0206.msg.vehicle_info_warning'));
                                } else if(options[i].fastening_info_detail.need_vehicle == 2){
                                    // 批號： item.plot_no 無維護載具編號，請先維護載具資訊
                                    msg += ($filter('translate')('B0216.showAlert.column5') + options[i].plot_no + 
                                        $filter('translate')('B0206.msg.vehicle_info_empty'));
                                } 
                                // modify by 奕達 for #88479 卡控訊息邏輯錯誤
                                // else {
                                //     // 批號： item.plot_no 尚未選取載具編號，請重新確認
                                //     msg += ($filter('translate')('B0216.showAlert.column5') + options[i].plot_no 
                                //         + $filter('translate')('B0217.showAlert.column9'));
                                // }
                            }
                        }
                    }
                }

                if(msg == ''){
                    if(warring_msg == ''){
                        callback();
                    } else {
                        $rootScope.showConfirm(warring_msg, function(confirm_dialog){
                            confirm_dialog.hide();
                            callback();
                        });
                    }
                } else {
                    $rootScope.showAlert(msg);
                }
            }

            //20220221 add BY 10877 FOR MTS0107482  ========(S)========
            // 更改發料不良數
            $scope.issuedefectqty = function (event, item) {
                var target = event.currentTarget;
                angular.element(target).addClass('is-focus');
                $calculater.open(function (num, calcDialog) {
                    if ((+item.lossqty) == (+num)) {
                        angular.element(target).removeClass('is-focus');
                        calcDialog.hide();
                        return;
                    } else {
                        if ((+num) < 0) {
                            $rootScope.showAlert($filter('translate')('panelInput.msg.qty_error'));
                            return;
                        }
                        item.issuedefectqty = num;
                        angular.element(target).removeClass('is-focus');
                        calcDialog.hide();
                        alter_valuationqty(item);
                    }
                },
                    function (calcDialog) {
                        angular.element(target).removeClass('is-focus');
                        calcDialog.hide();
                    },
                    {
                        defaultNum: item.issuedefectqty,
                        decimalLength: 4
                    });
            }

            // 更改多於數
            $scope.excessqty = function (event, item) {
                var target = event.currentTarget;
                angular.element(target).addClass('is-focus');
                $calculater.open(function (num, calcDialog) {
                    if ((+item.excessqty) == (+num)) {
                        angular.element(target).removeClass('is-focus');
                        calcDialog.hide();
                        return;
                    } else {
                        if ((+num) < 0) {
                            $rootScope.showAlert($filter('translate')('panelInput.msg.qty_error'));
                            return;
                        }
                        item.excessqty = num;
                        angular.element(target).removeClass('is-focus');
                        calcDialog.hide();
                    }
                },
                    function (calcDialog) {
                        angular.element(target).removeClass('is-focus');
                        calcDialog.hide();
                    },
                    {
                        defaultNum: item.excessqty,
                        decimalLength: 4
                    });
            }

            //更改短少數
            $scope.lossqty = function (event, item) {
                var target = event.currentTarget;
                angular.element(target).addClass('is-focus');
                $calculater.open(function (num, calcDialog) {
                    if ((+item.lossqty) == (+num)) {
                        angular.element(target).removeClass('is-focus');
                        calcDialog.hide();
                        return;
                    } else {
                        if ((+num) < 0) {
                            $rootScope.showAlert($filter('translate')('panelInput.msg.qty_error'));
                            return;
                        }
                        item.lossqty = num;
                        angular.element(target).removeClass('is-focus');
                        calcDialog.hide();
                    }
                },
                    function (calcDialog) {
                        angular.element(target).removeClass('is-focus');
                        calcDialog.hide();
                    },
                    {
                        defaultNum: item.lossqty,
                        decimalLength: 4
                    });
            }

            //更改發料不良數
            $scope.issuedefectqty = function (event, item) {
                var target = event.currentTarget;
                angular.element(target).addClass('is-focus');
                $calculater.open(function (num, calcDialog) {
                    if ((+item.issuedefectqty) == (+num)) {
                        angular.element(target).removeClass('is-focus');
                        calcDialog.hide();
                        return;
                    } else {
                        if ((+num) < 0) {
                            $rootScope.showAlert($filter('translate')('panelInput.msg.qty_error'));
                            return;
                        }
                        item.issuedefectqty = num;
                        angular.element(target).removeClass('is-focus');
                        calcDialog.hide();
                        alter_valuationqty(item);
                    }
                },
                    function (calcDialog) {
                        angular.element(target).removeClass('is-focus');
                        calcDialog.hide();
                    },
                    {
                        defaultNum: item.issuedefectqty,
                        decimalLength: 4
                    });
            }

            //更改計價數量
            $scope.valuationqty = function (event, item) {
                var target = event.currentTarget;
                angular.element(target).addClass('is-focus');
                $calculater.open(function (num, calcDialog) {
                    if ((+item.valuationqty) == (+num)) {
                        angular.element(target).removeClass('is-focus');
                        calcDialog.hide();
                        return;
                    } else {
                        if ((+num) < 0) {
                            $rootScope.showAlert($filter('translate')('panelInput.msg.qty_error'));
                            return;
                        }
                        if ((+num) < (+item.issuedefectqty)) {
                            $rootScope.showAlert($filter('translate')('panelInput.msg.valuationqty_error'));
                            return;
                        }
                        if ((+num) > ((+item.returned_qty) + (+item.issuedefectqty))) {
                            $rootScope.showAlert($filter('translate')('panelInput.msg.valuationqty_over'));
                            return;
                        }
                        item.valuationqty = num;
                        item.valuationqty_no = (+item.returned_qty) + (+item.issuedefectqty) - (+item.valuationqty)
                        angular.element(target).removeClass('is-focus');
                        calcDialog.hide();
                    }
                },
                    function (calcDialog) {
                        angular.element(target).removeClass('is-focus');
                        calcDialog.hide();
                    },
                    {
                        defaultNum: item.valuationqty,
                        decimalLength: 4
                    });
            }

            //更改不計價數量
            $scope.valuationqty_no = function (event, item) {
                var target = event.currentTarget;
                angular.element(target).addClass('is-focus');
                $calculater.open(function (num, calcDialog) {
                    if ((+item.valuationqty_no) == (+num)) {
                        angular.element(target).removeClass('is-focus');
                        calcDialog.hide();
                        return;
                    } else {
                        if ((+num) < 0) {
                            $rootScope.showAlert($filter('translate')('panelInput.msg.qty_error'));
                            return;
                        }
                        if (((+item.returned_qty) - (+num)) < 0) {
                            $rootScope.showAlert($filter('translate')('panelInput.msg.valuationqty_error'));
                            return;
                        }
                        if ((+item.valuationqty) - (+num) > ((+item.returned_qty) + (+item.issuedefectqty))) {
                            $rootScope.showAlert($filter('translate')('panelInput.msg.valuationqty_over'));
                            return;
                        }
                        item.valuationqty_no = num;
                        item.valuationqty = (+item.returned_qty) + (+item.issuedefectqty) - (+item.valuationqty_no)
                        angular.element(target).removeClass('is-focus');
                        calcDialog.hide();
                    }
                },
                    function (calcDialog) {
                        angular.element(target).removeClass('is-focus');
                        calcDialog.hide();
                    },
                    {
                        defaultNum: item.valuationqty_no,
                        decimalLength: 4
                    });
            }

            function alter_valuationqty(item) {
                if (item.plot_no.indexOf('RW') != -1) {
                    item.valuationqty = item.issuedefectqty;
                    item.valuationqty_no = item.returned_qty;
                } else {
                    item.valuationqty = (+item.issuedefectqty) + (+item.returned_qty);
                    item.valuationqty_no = 0;
                }

            }

            function Qty_check(item) {
                var msg = '';
                if (item.osstatus == '2')
                    return msg;
                if ((+item.can_returned_qty) < ((+item.returned_qty) + (+item.abnormal_qty) +
                    (+item.lossqty) - (+item.excessqty) + (+item.return_qty) +
                    (+item.issuedefectqty)) && ($scope.osbacknotallowedexceed == "1")) { // modify by Alan for#161004 : 補上外包超收檢查
                    msg = $filter('translate')('panelInput.msg.can_return_qty_unenough', { can_returned_qty: item.can_returned_qty });
                } else {
                    if ((+item.returned_qty < (+item.excessqty))) {
                        msg = $filter('translate')('panelInput.msg.good_qty_error');   //良品數 的輸入值 需>= 多餘數
                    } else {
                        if (((+item.returned_qty) > (+item.can_returned_qty)) && ($scope.osbacknotallowedexceed == "1")) {
                            msg = $filter('translate')('panelInput.msg.OSReceipt_Qtyover');       //外包超收                                           
                        } else {
                            if ((+item.valuationqty) < (+item.issuedefectqty)) {
                                msg = $filter('translate')('panelInput.msg.valuationqty_error');       //計價數量>=發料不良
                            }
                        }
                    }
                }
                if (msg != '') {
                    msg = $filter('translate')('B0217.showAlert.column10', { plot_no: item.plot_no, op_no: item.op_no }) + msg;
                }
                return msg;
            }

            //檢查檢驗狀態，不同檢驗狀態不可同時勾選送出
            function Osstatus_check(item) {
                if (item.isSelect == false) {
                    if ($scope.outsourcing_info_detail_C.length == 0) {
                        return true;
                    } else {
                        if ($scope.outsourcing_info_detail_C[0].osstatus != item.osstatus) {
                            return false;
                        } else {
                            return true;
                        }
                    }
                } else {
                    return true;
                }
            }
            //20220221 add BY 10877 FOR MTS0107482  ========(E)========

            
            $scope.ERPisWF = '1'
            $scope.qms = false;

            //添加ERPisWF监听函数
            $scope.$watch('ERPisWF', (newValue,oldValue)=>{
                $scope._event['changestate'].isShown = ($scope.ERPisWF!=0)?'Y':'N';
            });
            $scope.$watch('qms', (newValue,oldValue)=>{
                $scope._event['B0217_itemList.spc'].isShown = $scope.qms?'Y':'N';
                $scope._event['B0217_itemList.spc_ok'].isShown = $scope.qms?'Y':'N';
                $scope._event['B0217_itemList.qc_control'].isShown = $scope.qms?'Y':'N';
            });
            $scope.$watch('FasteningPackage', (newValue,oldValue)=>{
                $scope._event['B0217_itemList.vehicle_no'].isShown = ($scope.FasteningPackage == 1 || $scope.FasteningPackage == 'Y')?'Y':'N';
            });

            $scope._event = {
                'B0217_itemList' : {
                    // 20230306 modify by 文蔚 for M#129460 送验中，仍可以打勾选取，操作回货
                    enableSelect: (item) => item.osstatus !== '1'
                },
                'A.OSNO':{
                    click: () => {
                        loadOutsource('A.OSNO')
                    }
                },
                'B.SubcontractorNo':{
                    click: () => {
                        loadOutsourcer('B.SubcontractorNo')
                    }
                },
                'C.MONo':{
                    click: () => {
                        loadWoInfo('C.MONo')
                    }
                },
                'A.LOTNO':{
                    click: () => {
                        loadPlotInfo('A.LOTNO')
                    }
                },
                erp_doc_display: {
                    click: () => {
                        $rootScope.showQueryList({
                            pageRecord:50,
                            header : [
                                {label:$filter('translate')('B0216.queryList.column3_1'), code:'page_no'},
                                {label:$filter('translate')('B0216.queryList.column3_2'), code:'page_name'}
                            ],
                            query: function(conditions, feedback){
                                $MMWService.sendToServer({
                                    uri: 'ServicesSTD.Module_SYS.erp_document_type_get',
                                    content: {
                                        doc_type: '5',
                                        chkdefault_os_return_qcflag: $scope.state
                                    },//20220224 add by 10877 for M#107481 0:SMES檢驗(PKG) 、 1:ERP檢驗
                                    success: function (data) {
                                        feedback(data);
                                    }
                                });
                            },
                            selectCode:$scope.outsourcers.erp_doc_type,
                            confirm : function(selectItem, dialog){
                                dialog.hide();
                                $scope.outsourcers.erp_doc_display = selectItem.page_no + ' ('+selectItem.page_name+')';
                                $scope.outsourcers.erp_doc_type = selectItem.page_no;
                            }
                        });
                    }
                },
                outsource_no:{
                    click: (item) => {
                        loadOutsource(item)
                    }
                },
                outsourcers_no:{
                    click: (item) => {
                        loadOutsourcer(item);
                    }
                },
                mono:{
                    click: (item) => {
                        loadWoInfo(item);
                    }
                },
                plotno:{
                    click: (item) => {
                        loadPlotInfo(item);
                    }
                },
                //20230116 add by 13226 for M#125540 回货检验点击事件
                changestate:{
                    click: (mstate) => {
                        $scope.changestate(mstate);
                    },
                    isShown : ($scope.ERPisWF!=0)?'Y':'N'
                },
                //20230117 add by 13226 for M#125540 列表部分事件
                'B0217_itemList.vehicle_no':{
                    disabled: (_modelName,_eventArgs) => {
                        return _eventArgs.eventScope.osstatus=='0'
                    },
                    isShown: ($scope.FasteningPackage == 1 || $scope.FasteningPackage == 'Y')?'Y':'N'
                },
                'B0217_itemList.spc':{
                    isShown: $scope.qms?'Y':'N'
                },
                'B0217_itemList.spc_ok':{
                    isShown: $scope.qms?'Y':'N'
                },
                'B0217_itemList.qc_control':{
                    isShown: $scope.qms?'Y':'N'
                },
            }


            $scope._fn = {
                confirm: {
                    click: () => {
                        $scope.confirm();
                    }
                },
                Execute: {
                    click: () => {
                        $scope.setting();
                    }
                }
            }
        }
    ];
});
